#-*- coding: utf-8 -*-
from util import xml_converter, json_converter, csv_converter, ttl_converter

XML = 'application/xml'
JSON = 'application/json'
CSV = 'text/csv'
TTL = 'text/turtle'

'''
Converte dati in formato grezzo in un dizionario di Location

@param raw_data: dati grezzi (json,xml,ttl,csv)
@param mime_type: tipo dati in input
@return: i dati grezzi convertiti in Location
'''
def convert2locations(raw_data, mime_type):
    if mime_type == XML:
        locations = xml_converter.parse_xml(raw_data)
    elif mime_type == JSON:
        locations = json_converter.parse_json(raw_data)
    elif mime_type == CSV:
        locations = csv_converter.parse_csv(raw_data)
    elif mime_type == TTL:
        locations = ttl_converter.parse_ttl(raw_data)
        
    return locations

'''
Converte un dizionario di Location in dati grezzi

@param locations: dizionario di Location
@param mime_type: tipo dati in output
'''
def convert2rawdata(locations,mime_type):
    if mime_type == XML:
        raw_data = xml_converter.write_xml(locations)
    elif mime_type == JSON:
        raw_data = json_converter.write_json(locations)
    elif mime_type == CSV:
        raw_data = csv_converter.write_csv(locations)
    elif mime_type == TTL:
        raw_data = ttl_converter.write_ttl(locations)
    else:
        raise Exception('Format "%s" not supported:' % mime_type)
    
    return raw_data
